import java.io.IOException;
import java.util.LinkedList;


public class GameRunner {
	private GameState g;
	public GameRunner()
	{
		g = new GameState();
		g.init();
		initAIPlayers();
		nextHand();
		g.initRound();
	}
	private void initAIPlayers()
	{
		LinkedList<Player> temp = g.getPlayers();
		for(int i=0; i<temp.size(); i++)
		{
			if(temp.get(i).type == "AI")
			{
				((AIPlayer)temp.get(i)).init();
			}
		}
	}
	public void nextHand()
	{
		g.initHand();
	}
	public void nextRound()
	{
		LinkedList<Player> temp = g.getPlayers();
		for(int i=0; i<temp.size(); i++)
		{
			if(temp.get(i).type == "AI")
			{
				((AIPlayer)temp.get(i)).resetRound();
			}
		}
		g.incrementRound();
		g.initRound();
	}
	public void run() throws IOException
	{
		boolean flag = g.playRound();
		if(flag)
		{
			nextRound();
		}
		else
		{
			nextHand();
		}		
	}

}
